package com.cgbl.cg.vm.collection

import android.app.Application
import androidx.databinding.ObservableField
import api.WorkServiceFactory
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.model.CollectDetailBean
import com.robot.base.model.WorksBean
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent
import me.goldze.mvvmhabit.http.BaseResponse

class CollectionsDetailsViewModel(application: Application) : GLBaseViewModel(application) {
    val title = ObservableField<String>()
    val imgUrl = ObservableField<String>()
    val name = ObservableField<String>()
    val worksCount = ObservableField<String>()
    val followCount = ObservableField<String>()
    val followStatus = ObservableField(false)

    val uc = UiChangeEvent()
    class UiChangeEvent{
        val dataEvent = SingleLiveEvent<List<WorksBean>>()
    }
    fun getCollectDetail(id: String){
        WorkServiceFactory.getCollectDetail(
            id
        ).subscribe(object :AbstractViewModelSubscriber<BaseResponse<CollectDetailBean>>(this){
            override fun onNext(t: BaseResponse<CollectDetailBean>) {
                initData(t.data)
            }
        })
    }
    fun initData(bean: CollectDetailBean) {
        title.set(bean.collectName)
        imgUrl.set(bean.accountHead)
        name.set(bean.accountNickName)
        worksCount.set(bean.worksCount)
        followCount.set(bean.followCount)
        followStatus.set(bean.followStatus == "1")
        uc.dataEvent.postValue(bean.workInfoBaseVOS)
    }
}